package com.mql.onlinechatsystem.system.controller;

import com.alibaba.fastjson.JSONObject;
import com.mql.onlinechatsystem.system.entity.TbMessagerelation;
import com.mql.onlinechatsystem.system.service.ITbMessagerelationService;
import com.mql.onlinechatsystem.system.vo.TbMessagerelationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 马庆林
 * @since 2023-03-08
 */
@Api(tags = "获取message的发送者和接收者关系表")
@RestController
@RequestMapping("/system/tbMessagerelation")
@CrossOrigin
public class TbMessagerelationController {
    @Autowired
    private ITbMessagerelationService iTbMessagerelationService;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @ApiOperation("获取信息")
    @GetMapping("/getMessageList")
    public JSONObject getMessageList(TbMessagerelation tbMessagerelation){
        stringRedisTemplate.opsForValue().set(tbMessagerelation.getTouserid(), tbMessagerelation.getFromuserid());
        JSONObject result=new JSONObject();
        List<TbMessagerelationVo> tbMessagerelationVos=iTbMessagerelationService.getMessageList(tbMessagerelation);
        result.put("code",200);
        result.put("message","查询成功！");
        result.put("data",tbMessagerelationVos);
        return result;
    }
}
